package com.ybwh.springboot2.controller.swagger;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ybwh.springboot2.util.FileDownUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.io.FileInputStream;
import java.io.IOException;


/**
 * @since:knife4j-spring-boot-demo
 * @auth <a href="xiaoymin@foxmail.com">xiaoymin@foxmail.com</a>
 * 2022/8/6 23:42
 */
@Slf4j
@Tag(name = "文件下载1")
@ApiSupport(author = "xiaoymin@foxmail.com", order = 278)
@RestController
@RequestMapping(value = "/job3", produces = MediaType.APPLICATION_JSON_VALUE)
public class Job3Controller {

    @GetMapping("/download")
    public void download(HttpServletResponse response) throws IOException {
        // 这里 FileInputStream 应该根据文件ID去文件服务器取,FileInputStream需要自己关闭
        try (FileInputStream fis = new FileInputStream("D:/33.txt")) {
            FileDownUtils.downFile(fis, "345.txt", response, false);
        }

    }

}
